<template>
	<view class="sww-address-box" @click="$selectWxAddress">
		<u-icon name="e769" size="44" color="#666666" custom-prefix="iconfont"></u-icon>
		<block v-if="vuex_address">
			<view class="s-a-content">
				<view class="s-a-top">
					<text class="">{{ vuex_address.name }}</text>
					<text class="u-m-l-24">{{ vuex_address.mobile }}</text>
				</view>
				<view class="s-a-detail u-m-t-6">{{ vuex_address.address }}</view>
			</view>
		</block>
		<block v-else>
			<view class="s-a-content">请选择收货地址</view>
		</block>
		<u-icon name="e775" size="30" color="#666666" custom-prefix="iconfont"></u-icon>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';
	import {
		openAddress
	} from '@/utils/uniPromise.js'
	export default {
		data() {
			return {};
		},
		computed: {
			...mapState(['vuex_address'])
		},
		mounted() {
			// var userName = res.userName; // 收货人姓名
			// var postalCode = res.postalCode; // 邮编
			// var provinceName = res.provinceName; // 国标收货地址第一级地址（省）
			// var cityName = res.cityName; // 国标收货地址第二级地址（市）
			// var countryName = res.countryName; // 国标收货地址第三级地址（国家）
			// var detailInfo = res.detailInfo; // 详细收货地址信息
			// var nationalCode = res.nationalCode; // 收货地址国家码
			// var telNumber = res.telNumber; // 收货人手机号码
		},
		methods: {
			$selectWxAddress() {
				openAddress(true).then((res) => {
					// #ifdef MP-ALIPAY
					this.$u.vuex('vuex_address', {
						name: res.result.fullname,
						mobile: res.result.mobilePhone,
						address: res.result.address
					});
					// #endif
					// #ifdef MP-WEIXIN || MP-BAIDU ||  MP-TOUTIAO
					this.$u.vuex('vuex_address', {
						name: res.userName,
						mobile: res.telNumber,
						address: `${res.provinceName},${res.cityName},${res.countyName}${res.streetName?',' + res.streetName : ''}${res.detailInfoNew?',' + res.detailInfoNew : ''}`
					});
					// #endif
					// #ifdef H5
					this.$u.vuex('vuex_address', {
						name: res.userName,
						mobile: res.telNumber,
						address: `${res.provinceName} ${res.cityName} ${res.countryName} ${res.detailInfo}`
					});
					// #endif
				}).catch(() => {

				})

			}
		}
	};
</script>
<style scoped lang="scss">
	.sww-address-box {
		width: 100%;
		background-color: #ffffff;
		padding: 30rpx 32rpx;
		display: flex;
		border-bottom: 6rpx solid #ffffff;
		border-image: url('') 0 0 100% 0 repeat;

		.s-a-content {
			flex: 1;
			overflow: hidden;
			margin: 0 24rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			font-size: 26rpx;
			color: #666666;
		}
	}
</style>
